home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WTEXTBOX.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  11.8 KB  |  380 lines

  1. /*************************************************************************
  2.  *
  3.  * WTextBox -- Wrapper for the Windows 95 Textbox control.
  4.  *
  5.  *
  6.  *   Events:
  7.  *
  8.  *       Change --
  9.  *
  10.  *       DataAvailable --
  11.  *
  12.  *       DataClose --
  13.  *
  14.  *       DataOpen --
  15.  *
  16.  *       DataRequest --
  17.  *
  18.  *       Update --
  19.  *
  20.  *************************************************************************/
  21.  
  22. #ifndef _WTEXTBOX_HPP_INCLUDED
  23. #define _WTEXTBOX_HPP_INCLUDED
  24.  
  25. #ifndef _WNO_PRAGMA_PUSH
  26. #pragma pack(push,8);
  27. #pragma enum int;
  28. #endif
  29.  
  30. #ifndef _WCONTROL_HPP_INCLUDED
  31. #  include "wcontrol.hpp"
  32. #endif
  33. #ifndef _WDATATRG_HPP_INCLUDED
  34. #  include "wdatatrg.hpp"
  35. #endif
  36.  
  37. class WDataSource;
  38.  
  39. enum WTextBoxScroll {
  40.     WTBScrollLineUp,
  41.     WTBScrollLineDown,
  42.     WTBScrollPageUp,
  43.     WTBScrollPageDown
  44. };
  45.  
  46. //
  47. // Textbox Styles
  48. //
  49.  
  50. #define WTextBoxDefault       ((WStyle)0x50800080L) // WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL|WS_CHILD
  51.  
  52. #define WTextBoxLeft          ((WStyle)0x00000000L) // ES_LEFT
  53. #define WTextBoxCenter        ((WStyle)0x00000001L) // ES_CENTER
  54. #define WTextBoxRight         ((WStyle)0x00000002L) // ES_RIGHT
  55. #define WTextBoxMultiLine     ((WStyle)0x00000004L) // ES_MULTILINE
  56. #define WTextBoxUpperCase     ((WStyle)0x00000008L) // ES_UPPERCASE
  57. #define WTextBoxLowerCase     ((WStyle)0x00000010L) // ES_LOWERCASE
  58. #define WTextBoxPassword      ((WStyle)0x00000020L) // ES_PASSWORD
  59. #define WTextBoxAutoVScroll   ((WStyle)0x00000040L) // ES_AUTOVSCROLL
  60. #define WTextBoxAutoHScroll   ((WStyle)0x00000080L) // ES_AUTOHSCROLL
  61. #define WTextBoxNoHideSel     ((WStyle)0x00000100L) // ES_NOHIDESEL
  62. #define WTextBoxOEMConvert    ((WStyle)0x00000400L) // ES_OEMCONVERT
  63. #define WTextBoxReadOnly      ((WStyle)0x00000800L) // ES_READONLY
  64. #define WTextBoxWantReturn    ((WStyle)0x00001000L) // ES_WANTRETURN
  65. #define WTextBoxNumber        ((WStyle)0x00002000L) // ES_NUMBER
  66.  
  67. class WCMCLASS WTextBox : public WControl {
  68.     WDeclareSubclass( WTextBox, WControl );
  69.     
  70.     public:
  71.  
  72.         WTextBox();
  73.  
  74.         ~WTextBox();
  75.  
  76.         /**************************************************************
  77.          * Properties
  78.          **************************************************************/
  79.  
  80.         // AutomaticEscapeHandling
  81.         //
  82.         //     If AutomaticEscapeHandling is set to TRUE and the textbox
  83.         //     has the WTextBoxMultiLine style set, then it will cause
  84.         //     a Cancel event to be triggered on the parent dialog whenever
  85.         //     the Escape key is hit.  Otherwise, the Escape key will not
  86.         //     trigger a Cancel event, although it will trigger a Close
  87.         //     event and close the dialog.
  88.  
  89.         WBool GetAutomaticEscapeHandling() const;
  90.         WBool SetAutomaticEscapeHandling( WBool automaticEscapeHandling );
  91.  
  92.         // CanUndo
  93.         //
  94.         //     Read-only property.  Returns TRUE if the last edit operation
  95.         //     can be undone by calling the Undo method.
  96.  
  97.         WBool GetCanUndo() const;
  98.  
  99.         // DataColumns
  100.  
  101.         WString GetDataColumns() const;
  102.         WBool   SetDataColumns( const WString & cols );
  103.  
  104.         // DataSource
  105.  
  106.         WDataSource *GetDataSource() const;
  107.         WBool        SetDataSource( WDataSource *source );
  108.  
  109.         // FDXDataSource
  110.  
  111.         WBool SetFDXDataSource( WString * fdxDataSource );
  112.  
  113.         // EditSelection
  114.         //
  115.         //     The current selection in the edit control.  The
  116.         //     selection points start at 0 and occur between the characters.
  117.         //     When setting, set start=-1 to deselect everything,
  118.         //     or set end=-1 to select from start to end of text.
  119.  
  120.         WRange GetEditSelection() const;
  121.         WBool SetEditSelection( const WRange & editSelection );
  122.  
  123.         // FirstCharacterIndex
  124.         //
  125.         //     Read-only property.  Returns the zero-based index of
  126.         //     the first visible character.
  127.  
  128.         WULong GetFirstCharacterIndex() const;
  129.  
  130.         // FirstLineIndex
  131.         //
  132.         //     Read-only property.  Returns the zero-based index of
  133.         //     the first visible line.  (Always returns 0 for single
  134.         //     line text boxes.)
  135.  
  136.         WULong GetFirstLineIndex() const;
  137.  
  138.         // LineCount
  139.         //
  140.         //     The number of lines in the control.
  141.  
  142.         WULong GetLineCount() const;
  143.          
  144.         // Caret position
  145.         //
  146.         //      The position of caret
  147.         //
  148.         WBool   SetCaretPosition(WInt pos, WBool scrollInfoView = FALSE);
  149.         WULong  GetCaretPosition() const;
  150.  
  151.         // Margins
  152.         //
  153.         //     The margins for the multi line control.
  154.         //     If no parms are specified for the set, the margins
  155.         //     are reset to font margins.
  156.  
  157.         WBool SetMargins( const WRange & margins );
  158.         WBool SetMargins();
  159.         WRange GetMargins() const;
  160.  
  161.         // Modified
  162.         //
  163.         //     If TRUE, text has been modified since the property
  164.         //     was cleared (it is initially cleared).
  165.  
  166.         WBool GetModified() const;
  167.         WBool SetModified( WBool modified );
  168.  
  169.         // PasswordCharacter
  170.         //
  171.         //     Get/set the password character.  Note that 16-bit
  172.         //     values are used for DBCS/Unicode.
  173.  
  174.         WUShort GetPasswordCharacter() const;
  175.         WBool SetPasswordCharacter( WUShort ch );
  176.  
  177.         // ReadOnly
  178.         //
  179.         //     Determines whether edit box is read-only.
  180.  
  181.         WBool GetReadOnly() const;
  182.         WBool SetReadOnly( WBool readOnly );
  183.  
  184.         // SoftLineBreaks
  185.         //
  186.         //     Use at runtime with multiline text boxes.  If TRUE, a
  187.         //     soft line break (CR-CR-LF) is inserted at the end of each
  188.         //     line that is broken because of wordwrap.  If FALSE, all
  189.         //     such line breaks are removed and only hard line breaks
  190.         //     (CR-LF) are left.
  191.  
  192.         WBool GetSoftLineBreaks() const;
  193.         WBool SetSoftLineBreaks( WBool on );
  194.  
  195.         // TextLimit
  196.         //
  197.         //     Set/get the max # of charactes the text box can hold.
  198.         //     Setting the limit to 0 sets it to the max (32K for
  199.         //     single line, 64K for multi line).
  200.  
  201.         WULong GetTextLimit() const;
  202.         virtual WBool SetTextLimit( WULong limit );
  203.  
  204.         /**************************************************************
  205.          * Methods
  206.          **************************************************************/
  207.  
  208.         // AppendText
  209.         //
  210.         //     Add text to the end of the textbox.  If scroll is TRUE,
  211.         //     the caret is moved to the end of the text and the
  212.         //     text is scrolled into view.
  213.  
  214.         WBool AppendText( const WString & text, WBool scroll=TRUE );
  215.  
  216.         // CharacterIndex
  217.         //
  218.         //     Given a point in the edit control's client area, returns
  219.         //     the character index (from 0) and line index (from 0)
  220.         //     of the character.  Returns FALSE if the point is outside
  221.         //     the client area, in which case the charIndex and lineIndex
  222.         //     values are to be ignored.  Note that charIndex and lineIndex
  223.         //     are limited to 16 bits.
  224.  
  225.         WBool CharacterIndex( const WPoint & pt, WULong & charIndex ) const;
  226.         WBool CharacterIndex( const WPoint & pt, WULong & charIndex,
  227.                               WULong & lineIndex ) const;
  228.  
  229.         // Clear
  230.         //
  231.         //     Clears (deletes) the selected text in the edit control.
  232.  
  233.         void  Clear();
  234.  
  235.         // ClearUndoBuffer
  236.         //
  237.         //     Clears the undo buffer.
  238.  
  239.         WBool ClearUndoBuffer() const;
  240.  
  241.         // Copy
  242.         //
  243.         //     Copy the selected contents into the clipboard.
  244.  
  245.         WBool Copy();
  246.  
  247.         // Cut
  248.         //
  249.         //     Copy & clear the selected contents.
  250.  
  251.         void  Cut();
  252.  
  253.         // InsertText
  254.         //
  255.         //     Insert text into the control.  If text is currently
  256.         //     selected, the new text replaces it, otherwise the text
  257.         //     gets inserted at the current caret position.
  258.  
  259.         WBool InsertText( const WString & text, WBool canUndo=FALSE );
  260.  
  261.         // LineIndex
  262.         //
  263.         //     Return the line that a character is on.  If -1 (0xFFFFFFFF)
  264.         //     is passed, returns line the caret is on.
  265.  
  266.         WULong LineIndex( WULong charIndex=0xFFFFFFFF ) const;
  267.  
  268.         // Paste
  269.         //
  270.         //     Paste the contents of the clipboard.
  271.  
  272.         void  Paste();
  273.  
  274.         // CharacterPosition
  275.         //
  276.         //     Return the point (in client coordinates) that corresponds
  277.         //     to a given character position.
  278.  
  279.         WBool CharacterPosition( WPoint & point, WULong charIndex ) const;
  280.  
  281.         // Scroll
  282.         //
  283.         //     Scroll a certain number of characters and/or lines.
  284.         //     dx = # of characters, dy = # of lines.
  285.  
  286.         WBool Scroll( WTextBoxScroll scrollBy=WTBScrollLineDown ) const;
  287.         WBool Scroll( WLong dx, WLong dy=0 ) const;
  288.  
  289.         // ScrollCaret
  290.         //
  291.         //     Scroll the caret into view if not visible.
  292.  
  293.         WBool ScrollCaret() const;
  294.  
  295.         // Undo
  296.         //
  297.         //     Undo the last operation if possible.
  298.  
  299.         WBool Undo();
  300.  
  301.         /**************************************************************
  302.          * Item Properties
  303.          **************************************************************/
  304.  
  305.         // Text
  306.         //
  307.         //     The text for the given line (lines start at 0).
  308.  
  309.         WString GetText( WULong line ) const;
  310.  
  311.         // TextLength
  312.         //
  313.         //     The length of text in a given line.
  314.  
  315.         WULong GetTextLength( WULong line ) const;
  316.  
  317.  
  318.         /**************************************************************
  319.          * Overrides
  320.          **************************************************************/
  321.  
  322.         virtual WBool Scroll( const WPoint & amount, WRect * toScroll=NULL,
  323.                               WRect * clipRegion=NULL );
  324.  
  325.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  326.  
  327.         virtual WStyle GetDefaultStyle() const;
  328.  
  329.         virtual WStyle GetDefaultExtendedStyle() const;
  330.  
  331.         virtual WString GetText() const;
  332.  
  333.         virtual size_t GetTextLength() const;
  334.         
  335.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  336.                                    void * data=NULL );
  337.  
  338.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  339.                                       WNotifyInfo info, WLong & returns );
  340.  
  341.         virtual const WChar * InitializeClass();
  342.  
  343.         virtual WBool FDXIn();
  344.  
  345.         virtual WBool FDXOut();
  346.  
  347.         WBool KeyDownHandler( WTextBox *, WKeyPressEventData *ev );
  348.         WBool DataOpenHandler( WTextBox *, WDataOpenEventData *ev );
  349.         WBool DataCloseHandler( WTextBox *, WDataCloseEventData *ev );
  350.         WBool DataAvailableHandler( WTextBox *, WDataAvailableEventData *ev );
  351.         WBool DataRequestHandler( WTextBox *, WDataRequestEventData *ev );
  352.  
  353.         WBool DragStartHandler( WTextBox *, WDragEventData *ev );
  354.         WBool DragDropHandler( WTextBox *, WDragEventData *ev );
  355.  
  356.     protected:
  357.  
  358.         virtual WBool AllocDTCell();
  359.  
  360.         /**************************************************************
  361.          * Data members
  362.          **************************************************************/
  363.  
  364.     protected:
  365.  
  366.         WBool                   _ignoreChange;
  367.         WBool                   _softLineBreaks;
  368.         WString *               _fdxDataSource;
  369.         WDataTargetCell         *_dataTarget;
  370.         WBool                   _wasEnabled;
  371.         WBool                   _automaticEscapeHandling;
  372. };
  373.     
  374. #ifndef _WNO_PRAGMA_PUSH
  375. #pragma enum pop;
  376. #pragma pack(pop);
  377. #endif
  378.  
  379. #endif // _WTEXTBOX_HPP_INCLUDED
  380.